package com.chazz.servlet;/**
 *
 */

import com.alibaba.fastjson.JSONArray;
import com.chazz.entity.Category;
import com.chazz.service.CategoryidService;
import com.chazz.service.impl.CategoryidServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 *
 * @title: BaseServlet
 * @Author ZhaoHongRui
 * @Date: 2020/9/23 9:02
 * @Version 1.0
 */

@WebServlet("/foraging.do")
public class BaseServlet extends HttpServlet {
    CategoryidService categoryidService = new CategoryidServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8");
        String method = req.getParameter("method");
        System.out.println("进入BaseServlet");

        CategoryidServlet categoryidServlet = new CategoryidServlet();
        //获取url里的参数
        String param = req.getParameter("id");
        System.out.println("param=" + param);

        //根据参数进入对应的方法
        if ("category".equals(param)) {
            categoryidServlet.BigCategory(req, resp);

        } else   //进入search搜索栏功能
            if ("search".equals(method)) {
                categoryidServlet.getProductDataList(req, resp);
            }

    }
}
